home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / os2tools / bnklysrc / sb_put.c < prev    next >
C/C++ Source or Header  |  1989-01-01  |  7KB  |  174 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software <no-Inc>                   */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          No-Cost<no-tm> Software.                       */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello  */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*              Box Drawing subroutines for BinkleyTerm 2.10                */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*    For complete  details  of the licensing restrictions, please refer    */
  17. /*    to the License  agreement,  which  is published in its entirety in    */
  18. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.210.    */
  19. /*                                                                          */
  20. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  21. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  22. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  23. /*    NOT HAVE THESE FILES,  YOU SHOULD  IMMEDIATELY CONTACT THE AUTHORS    */
  24. /*    AT THE  ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO    */
  25. /*    USE   THIS  FILE  WITHOUT  HAVING   ACCEPTED  THE  TERMS  OF   THE    */
  26. /*    BINKLEYTERM  LICENSING AGREEMENT,  OR SUCH OTHER  AGREEMENT AS YOU    */
  27. /*    ARE ABLE TO REACH WITH THE AUTHORS.                                   */
  28. /*                                                                          */
  29. /*                                                                          */
  30. /*    The Authors can be reached at the following addresses:                */
  31. /*                                                                          */
  32. /*    Robert C. Hartman                      Vincent E. Perriello           */
  33. /*    Spark Software                         VEP Software                   */
  34. /*    427-3 Amherst Street                   111 Carroll Street             */
  35. /*    CS2032, Suite 232                      Naugatuck, CT 06770            */
  36. /*    Nashua, NH 03061                                                      */
  37. /*                                                                          */
  38. /*    FidoNet 1:132/101                      FidoNet 1:141/491              */
  39. /*    Data    (603) 888-8179                 Data    (203) 729-7569         */
  40. /*                                                                          */
  41. /*    Please feel free to contact us at any time to share your comments     */
  42. /*    about our software and/or licensing policies.                         */
  43. /*                                                                          */
  44. /*                                                                          */
  45. /*   This module is derived from code developed by Augie Hansen in his      */
  46. /*   book "Proficient C" published by Microsoft Press.  Mr. Hansen was      */
  47. /*   kind enough to give us verbal permission to use his routines, and      */
  48. /*   Bob, Vince and Alan (and all our full screen users) are grateful.      */
  49. /*   If you decide to use this code in some package you are doing, give     */
  50. /*   some thought to going out and buying the book. He deserves that.       */
  51. /*                                                                          */
  52. /*--------------------------------------------------------------------------*/
  53.  
  54.  
  55. #include <ctype.h>
  56. #include "sbuf.h"
  57. #include "com.h"
  58. #include "xfer.h"
  59. #include "zmodem.h"
  60. #include "keybd.h"
  61. #include "sched.h"
  62. #include "externs.h"
  63. #include "prototyp.h"
  64.  
  65. extern BUFFER Sbuf;
  66. extern CELLP Scrnbuf;
  67.  
  68. int sb_putc (win, ch)
  69. REGIONP win;
  70. unsigned char ch;
  71. {
  72.    int cmax, rmax;
  73.    int noscroll = 0, puterr = 0;
  74.  
  75.    /* calculate the screen buffer position and limits */
  76.    cmax = win->c1 - win->c0;
  77.    rmax = win->r1 - win->r0;
  78.    Sbuf.row = win->r0 + win->row;
  79.    Sbuf.col = win->c0 + win->col;
  80.  
  81.    /* process the character */
  82.    switch (ch)
  83.       {
  84.       case '\b':
  85.          /* Non destructive backspace */
  86.          if (win->col > 0)
  87.             {
  88.             --(win->col);
  89.             --(Sbuf.col);
  90.             return (SB_OK);
  91.             }
  92.          else
  93.             return (SB_ERR);
  94.  
  95.       case '\r':
  96.          /* clear trailing line segment */
  97.          while (win->col < cmax)
  98.             {
  99.             if (sb_putc (win, ' ') == SB_ERR)
  100.                {
  101.                ++puterr;
  102.                }
  103.             }
  104.          sb_wc (win, ' ', 1);
  105.          break;
  106.  
  107.       case '\t':
  108.          /* convert tabs to spaces */
  109. /*         lim = win->col + 8 - (win->col & 7);
  110.          while (win->col < lim)
  111.             {
  112.             if (sb_putc (win, ' ') == SB_ERR)
  113.                {
  114.                ++puterr;
  115.                }
  116.             }
  117.          break;*/
  118.  
  119.       default:
  120.          (Scrnbuf + Sbuf.row * SB_COLS + Sbuf.col)->b.ch = ch;
  121.          if (Sbuf.col < Sbuf.lcol[Sbuf.row])
  122.             {
  123.             Sbuf.lcol[Sbuf.row] = Sbuf.col;
  124.             }
  125.          if (Sbuf.col > Sbuf.rcol[Sbuf.row])
  126.             {
  127.             Sbuf.rcol[Sbuf.row] = Sbuf.col;
  128.             }
  129.          break;
  130.       }
  131.  
  132.    /* update the cursor position */
  133.    if (win->col < cmax)
  134.       {
  135.       ++(win->col);
  136.       }
  137.    else if (win->row < rmax)
  138.       {
  139.       win->col = 0;
  140.       ++(win->row);
  141.       }
  142.    else if (win->wflags & SB_SCROLL)
  143.       {
  144.       sb_scrl (win, 1);
  145.       win->col = 0;
  146.       win->row = rmax;
  147.       }
  148.    else
  149.       {
  150.       ++noscroll;
  151.       }
  152.  
  153.    /* update screen buffer position */
  154.    Sbuf.row = win->r0 + win->row;
  155.    Sbuf.col = win->c0 + win->col;
  156.    Sbuf.flags |= SB_DELTA;
  157.  
  158.    return ((noscroll || puterr) ? SB_ERR : SB_OK);
  159. }
  160.  
  161. int sb_puts (win, s)
  162. REGIONP win;
  163. unsigned char *s;
  164. {
  165.    while (*s)
  166.       {
  167.       if (sb_putc (win, *s++) == SB_ERR)
  168.          return (SB_ERR);
  169.       }
  170.  
  171.    return (SB_OK);
  172. }
  173.  
  174.